package workexp.alg.sort;

import org.junit.Test;

/**
 * 归并排序
 */
public class SortedSquares {
    public int[] sortedSquares(int[] nums) {
        //查找正负数交界点
        int n = nums.length;
        //归并排序
        int[] result = new int[nums.length];

        for (int i = 0,j=n-1,pos=n-1; i <= j; pos--) {

            if (nums[i] * nums[i] > nums[j] * nums[j]) {
                result[pos] = nums[i]*nums[i];
                i++;
            }else{
                result[pos] = nums[j]*nums[j];
                j--;
            }
            System.out.println(i+"  "+j);

        }
        return result;
    }

    @Test
    public void test(){
//        int[] nums = {-7,-3,2,3,11};
        int[] nums = {-4,-2,2,3,11};
        int[] result = sortedSquares(nums);
        System.out.println(result.toString());
    }
}
